#!/bin/bash

# make directories

if [ ! -d ../../cache ] ; then
    mkdir ../../cache
fi

if [ ! -d ../../build/py ] ; then
    mkdir ../../build/py
fi

if [ ! -d ../../cache/upper_steganography ] ; then
    mkdir ../../cache/upper_steganography
else
    rm -rf ../../cache/upper_steganography/*
fi

cachedir="../../cache/upper_steganography"
filelist="filelist.json"


setupfile="../../$(cat $filelist | grep xrnconv | grep setup | tr -d ' ' | tr -d ',' | tr -d '"')"
pyxfile="../../$(cat $filelist | grep xrnconv | grep pyx | tr -d ' ' | tr -d ',' | tr -d '"')"
clifile="../../$(cat $filelist | grep xrnconv | grep cli | tr -d ' ' | tr -d ',' | tr -d '"')"

# copy files 

cp $setupfile $cachedir
cp $pyxfile $cachedir

echo "setupfile $setupfile"
echo "pyxfile $pyxfile"
echo "clifile $clifile"

# compile

cd $cachedir
python3 setup.py build_ext --inplace

# copy results into the build directory
cp ../../cache/upper_steganography/splitjoin.cpython* ../../build/py
cp $clifile ../../build/bin
rm -rf $cachedir

